package com.lw.algorithm.test;

import java.io.*;

public class Main {
	private int[] values;
	private static final int MAX = 50;
	private static final int MAX_PRICE = 1000;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = null;
		//System.out.println("请输入帽子个数");
		str = br.readLine();
		Main m = new Main();
		int count = Integer.valueOf(str);
		m.initArray(count);
		str = br.readLine();
		String[] array = str.split(" ");
		for (int i = 0; i < array.length; i++) {
			int price = Integer.valueOf(array[i]);
			if (price > MAX_PRICE) {
				//System.out.println("帽子单价大于" + MAX);
				return;
			}
			m.values[i] = price;
		}
		m.getThirdHat();
		
	}

	private void initArray(int count) {
		if (count > MAX) {
			//System.out.println("帽子个数大于" + MAX);
			return;
		}
		values = new int[count];
	}
	
	/**
	 * 插入排序
	 */
	private void getThirdHat(){
		for(int i = 0;i < values.length;i++){
			for(int j = i;j > 0;j--){
				if(values[j] < values[j - 1]){
					int temp = values[j - 1];
					values[j - 1] = values[j];
					values[j] = temp;
				}else {
					break;
				}
			}
		}
		int min = values[0];
		int minIndex = 0;
		for(int k = 1;k < values.length;k++){
			if(values[k] > min){
				minIndex++;
				min = values[k];
				if(minIndex == 2){
					System.out.println(min);
					break;
				}
			}
		}
		if(minIndex != 2){
			System.out.println(-1);
		}
	}
}
